﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Ppt = Microsoft.Office.Interop.PowerPoint;

namespace ObjectModel.PowerPoint
{
    public class SimpleTextTarget : LinkedTarget
    {
        public SimpleTextTarget() { } // Parameterless constructor needed for serialization.

        public SimpleTextTarget(Ppt.TextRange textRange)
        {
            TextRange = new ResolvableTextRange(textRange); // Provide caching of the shape object by passing in a CachedShape object.
        }

        public ResolvableTextRange TextRange { get; set; }

        [XmlIgnore]
        public override string Value
        {
            set
            {
                Ppt.TextRange textRange = TextRange.Resolve() as Ppt.TextRange;
                textRange.Text = value;
            }
        }

        [XmlIgnore]
        public override bool IsSelected
        {
            get
            {
                    Ppt.Application app = Globals.Application;
                    Ppt.Selection selection = app.ActiveWindow.Selection;

                    return ((Ppt.TextRange)TextRange.Resolve()).IntersectsWith(selection.TextRange);
                    //return TextRange.Contains(selection.TextRange);
            }
        }

        public override void Select()
        {
            Ppt.TextRange textRange = TextRange.Resolve() as Ppt.TextRange;
            textRange.Select();
        }
    }
}
